package com.wyb.logindemo.controller;

import com.wyb.logindemo.dao.UserDao;
import com.wyb.logindemo.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类功能描述
 *
 * @author: wyb
 * @Description: 控制层, 这里是实现注册接口
 * @Encoding: UTF-8
 * @create: 2021/12/13
 **/
@CrossOrigin            // 这里要加这个注解 允许前端跨域访问
@RestController
@RequestMapping(value = "/api/register")
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    /**
     * 下面是注册接口, 实现完后可以用Postman测试一下
     *
     * @Param username 用户名
     * @Param password 密码
     * @return
     */
    @PostMapping
    public String register(String username, String password){
        System.out.println("controller层接收前端发过来的数据(用户名和密码): ");
        System.out.println(username + "  " +  password);

        if (registerService.register(username, password)){
            return "注册成功";
        } else{
            return "该用户已存在 无法注册";
        }
    }


}
